﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>SendEmail</title>
    <script src="../../Scripts/jquery-1.7.1.js" type="text/javascript"></script>
    <script src="../../Scripts/ajaxfileupload.js" type="text/javascript"></script>
    <link href="../../Content/Themes/blue2/css.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .allContent{width:900px; margin:0px auto;}
      .EmailContent{padding-top:10px; }
      .InputLength{ width: 200px;}
      #showmessage{width: 600px; height:100px; }
      #btn_send,#btn_cancel,#btn_clear{ margin-left:100px;}
      .EmailNav{}
      #shoujianren{ width:200px;height:50px; position:absolute; z-index:1; margin-top:5px;}
      .ExcelDaoRu{  margin-left:50px; }
    </style>
</head>
<body class="main">
    <div class="AllWebTopDiv">
      <div class="path">
             <div class="nav">
               <a href="#">群发邮件</a>
             </div>
        </div>
       <div class="content">
       <div class="allContent">
      <div class="EmailNav">
       
         <label>发件人:</label>
         <input type="text" id="senderp" class="InputLength"  value="<%:Model.emailUser %>"/>

         &nbsp; &nbsp;
          <label>添加收件人：</label>
         <input type="text" id="To" class="InputLength" />
         <input  type="button" value="添加" onclick="addEmail();" class="button2"/>
         <label>收件人列表</label>
       
             <textarea id="shoujianren"  readonly="readonly"></textarea>   
         <br /><br />
         </div> 
          <div>
                  <label>密&nbsp; 码:</label>
         <input type="password" id="password" value="<%:Model.emailPwd %>" />
         <br /><br />
         <label>主题：</label>
         <input  type="text" id= "zhuti" style=" width:350px;"/>
         <label class="ExcelDaoRu"> 收件人Excel导入：</label>
         <input  type="file" id="fileUP" name="fileUP"  />
         <input  type="button" value="确定"   class="button2"  onclick="excelMsg();"/>
           </div>
       <div class="EmailContent">
       <label>正文： </label>
            <!--#include file="index.html" -->    
       </div>
       <label style=" margin-top:0px;">展示消息：</label>
       <div>
              
         <textarea id="showmessage"></textarea>
       </div>

       <div>
       <br />
         <input  type="button" value="发送" id="btn_send"  class="button2" onclick="PostData();"/>
         <input  type="button" value="清空" id="btn_clear" class="button2" onclick="clearInput();"/>
         <input  type="button" value="取消" id="btn_cancel" onclick="closeWindows();"  class="button2"/>
       </div>
       </div>
       </div>
    </div>
</body>
</html>
<script type="text/javascript">
    function addEmail() {
        var to = document.getElementById("To").value ;
        var strReg = /^\w+((-\w+)|(\.\w+))*\@{1}\w+\.{1}\w{2,4}(\.{0,1}\w{2}){0,1}/ig;
        var r = to.search(strReg);
        if (r == -1) {
            alert("邮箱格式错误");
        }
        else {
            var shou = document.getElementById("shoujianren");
            shou.value += to+'\n';
        }

    }
    //从excel导入邮箱
    function excelMsg() {
        //  document.getElementById("fileUP").click();
      //  var fileName = document.getElementById("fileUP").value;
       // $.ajax({
       //     type: 'get',
       //    url: '<%:Url.Action("excelMsg","Email") %>',
        //    data: 'fileName=' + fileName,
        //    cache: false,
         //   success: function (txt) {
          //      var shou = document.getElementById("shoujianren");
         //       shou.value += txt;
          //  },
          //  error: function (txt) {
          //      alert(txt);
         //   }
        //})
        if ($("#fileUP").val().length > 0) {
            ajaxFileUpload();

        }

    }
   
    function PostData() {
        var senderp = $("#senderp").val();
      
        var pwd = $("#password").val();
        var shoujianren = $("#shoujianren").val();
        var zhuti = $("#zhuti").val();
        if (senderp == ""||pwd==""||shoujianren=="") {
            alert("有必填项未填");
            return false;
        }
        go();
        var content = $("#text").val();
        alert(content);
        $.ajax({
            type: 'post',
            url: '../../Ajax/SendEmail.ashx',
            data: "senderp=" + senderp + "&pwd=" + pwd + "&shoujianren=" + shoujianren + "&zhuti=" + zhuti + "&content=" + content + "",
            cache: false,
            success: function (txt) {
                document.getElementById("showmessage").value = txt;
            }
        })
   }

   function clearInput() {
       document.getElementById("text").value = "";
       document.getElementById("showmessage").value = "";
       document.getElementById("shoujianren").value = "";
        var txts = document.getElementsByTagName("input");
        for (var i = 0; i < txts.length; i++) {
            if (txts[i].type == "text") {
                txts[i].value = "";
            }
        }
    }

    //ajax上传文件
    function ajaxFileUpload() {
        $.ajaxFileUpload
            (
                {
                    url: '<%:Url.Action("Upload","Email") %>',
                    secureuri: false,
                    fileElementId: 'fileUP',
                    dataType: 'HTML',
                    success: function (data, status) {
                        $("#shoujianren").val(data);
                    },
                    error: function (data, status, e)//服务器响应失败处理函数
                    {
                        alert(e);
                    }
                }
            )
        return false;
    }
    //关闭窗口
    function closeWindows() {
        window.location.href = "/Loading/Index/?src=/Desktop/Index/";
    }
</script>
